
import { $Toptips } from '../../../components/CompRouter';
import TimeUtils from "../../../utils/TimeUtils";

const BusScene = {
    SCENE_NOPOSS: "0",
    SCENE_POSS: "1"
};
Page({

    data: {
        selectDate: ''
    },

    onLoad: function () {
        this.setData({
            preDate: TimeUtils.getLatestMonth(1, "yyyy-MM")
        });
    },

    onSearch: function (e) {
        let profitDate = this.data.selectDate;
        let busScene = e.detail.value.busScene;
        if (this._checkForm(profitDate)) {
            this._navigateTo(profitDate, busScene);
        }
    },

    bindDateChange: function (e) {
        this.setData({
            selectDate: e.detail.value
        });
    },

    _checkForm(profitDate) {
        if (!profitDate) {
            $Toptips.error({text: '请选择查询的分润月份'});
            return false;
        } else if (TimeUtils.isLaterThen(profitDate, this.data.preDate)) {
            $Toptips.error({text: '请选择本月(不包含)之前的月份'});
            return false;
        }
        return true;
    },

    _navigateTo(profitDate, busScene){
        if (BusScene.SCENE_POSS === busScene) {
            wx.navigateTo({
                url: './posResult/posResult?profitDate=' + profitDate
            });
        } else {
            wx.navigateTo({
                url: './nposResult/nposResult?profitDate=' + profitDate
            });
        }
    }
});